﻿using MbUnit.Framework;
using NEnsure.Builders;
using Rhino.Mocks;
using NEnsure.Rules;
using NEnsure.Validators;

namespace NEnsure.UnitTests
{
	[TestFixture]
	public class BrokenRuleBuilderTests
	{
		[Test]
		public void Should_Display_Custom_Rule_When_Using_CustomRuleBuilder()
		{
			MockRepository mocks = new MockRepository();

			IErrorProvider provider = mocks.StrictMock<IErrorProvider>();

			SetupResult.For(provider.GetError(null)).IgnoreArguments().Return("Custom error");

			mocks.ReplayAll();

			IBrokenRuleBuilder builder = new CustomBrokenRuleBuilder(provider);
			ManualValidator validator = new ManualValidator(builder);

			validator.Ensure("PropertyName", string.Empty).Satisfies(Rule.IsRequired);
			validator.EnsureAll();

			Assert.AreEqual("Custom error", validator.BrokenRules[0].ErrorMessage);
		}
	}
}
